package com.example.gaoyang.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.gaoyang.domain.WayDirection;
import com.example.gaoyang.domain.request.WayDirectionRequest;
import com.example.gaoyang.domain.vo.WayDirectionVO;
import com.example.gaoyang.mapper.WayDirectionMapper;
import com.example.gaoyang.service.WayDirectionService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Slf4j
@Service
@Transactional
public class WayDirectionServiceImpl extends ServiceImpl<WayDirectionMapper, WayDirection> implements WayDirectionService {

    @Override
    public List<WayDirectionVO> getWayDirectionList(WayDirectionRequest wayDirectionRequest) {
        LambdaQueryWrapper<WayDirection> wrapper = this.getQueryWrapper(wayDirectionRequest);
        List<WayDirectionVO> list = BeanUtil.copyToList(this.list(wrapper), WayDirectionVO.class);
        return list;
    }

    private LambdaQueryWrapper<WayDirection> getQueryWrapper(WayDirectionRequest wayDirectionRequest) {
        return new LambdaQueryWrapper<WayDirection>()
                .eq(StringUtils.isNotEmpty(wayDirectionRequest.getWay()), WayDirection::getWay, wayDirectionRequest.getWay())
                .eq(StringUtils.isNotEmpty(wayDirectionRequest.getDirection()), WayDirection::getDirection, wayDirectionRequest.getDirection())
                .eq(StringUtils.isNotEmpty(wayDirectionRequest.getDirectionId()), WayDirection::getDirectionId, wayDirectionRequest.getDirectionId());
    }
}
